package reflect;

import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * 暴力反射对String的影响
 * */
public class ReflectDemo10 {
    public static void main(String[] args) throws Exception {
        String s1 = "123abc";
        String s2 = "123abc";
        System.out.println("s1="+s1);
        System.out.println("s2="+s2);
        System.out.println("s1==s2:"+(s1==s2));

        Class cls = String.class;//获取String的类对象
        Field field =cls.getDeclaredField("value");//获取value属性
        field.setAccessible(true);//暴力反射(强制访问)
        char[] vale =(char[])field.get(s1);//获取s1的value属性的值
        System.out.println(Arrays.toString(vale));

        vale =new char[]{'h','e','l','l','o'};;
        field.set(s1,vale);
        System.out.println("s1="+s1);
        System.out.println("s2="+s2);

        String s3 = "123abc";
        System.out.println("s3:"+s3);
    }
}
